package com.ayuer.chapter05;

import java.util.Arrays;

public class HeapSort {
    public static void main(String[] args) {

        int[] array = new int[]{1, 2, 3, 4, 5, 6, 7, 7};
        BigHeap bigHeap = new BigHeap(array);
        System.out.println(Arrays.toString(bigHeap.array));

        //================
        //堆排序
//        while (bigHeap.size > 1) {
//            bigHeap.swap(0, bigHeap.size - 1);
//            bigHeap.size--;
//            //调整
//            bigHeap.down2(0);
//        }
//        System.out.println(Arrays.toString(bigHeap.array));

        for (int right = array.length - 1; right > 0; right--) {
            bigHeap.swap(0, right);
            bigHeap.size--;
            //调整
            bigHeap.down2(0);
        }
        System.out.println(Arrays.toString(bigHeap.array));

    }
}
